// pages/cal/cal.js
var sliderWidth = 96; // 需要设置slider的宽度，用于计算中间位置
var api = require('../../utils/api.js');
var app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    activeIndex: 0,
    car_name: '运动版',   //车型
    loans_total_price: 0,      //贷款预计总花费
    total_price: 0,      //全款预计总话费
    naked_price:70000,        //裸车价
    down_payment: 0,     //首付
    monthly_payment: 0,      //月供
    more_expenditure:0,       //比全款多花
    monthly_interest:0.005,   //贷款月息

    /**
     * 必须花费
     */
    must_pay_fee:0,         //必须花费总数
    purchase_tax_fee: 0,     //购置税费用
    consumption_tax_fee: 0,  //消费税费用
    apply_vehicle_fee:500,     //上牌费用
    vehicle_tax_fee:0,      //车船税费用
    constraint_tax_fee: 0,     //交强险费用

    /**
     * 商业保险
     */
    sel_all: true,
    third_sel: true,               //第三者责任险
    third_deduction_sel: true,      //第三者不计免赔
    loss_sel: true,                 //车辆损失险
    loss_deduction_sel: true,      //损失不计免赔
    steal_sel: true,               //车辆盗抢险
    glass_sel: true,               //玻璃单独破碎险
    self_ignite_sel: true,         //自燃损失险  
    person_duty_sel: true,         //车上人员责任险
    scratch_sel: true,             //车身划痕险

    business_fee:0,                 //商业保险总计
    third_tax_fee: 0,               //第三者责任险费用  
    third_deduction_fee: 149,      //第三者不计免赔
    loss_fee: '4,004',                 //车辆损失险
    loss_deduction_fee: 801,      //损失不计免赔
    steal_fee: '1,570',               //车辆盗抢险
    glass_fee: 0,               //玻璃单独破碎险
    self_ignite_fee: 489,         //自燃损失险  
    person_duty_fee: 0,         //车上人员责任险
    scratch_fee: 0,             //车身划痕险 
    

    naked_ratio: [
              { ratio: '20%', sel: 0, val: 0.2},
              { ratio: '30%', sel: 1, val: 0.3},
              { ratio: '40%', sel: 0, val: 0.4},
              { ratio: '50%', sel: 0, val: 0.5}
    ],
    loans: [
      { year: '1年', sel: 0, val: 12 },
      { year: '2年', sel: 0, val: 24 },
      { year: '3年', sel: 1, val: 36 },
    ],
    car_info_height: 176, //选择计算部分自动高度
    vehicle_tax:[],       //车船税
    vehicle_default: 2,    //车船默认值
    constraint_tax:[],    //交强险
    constraint_default: 0,    //交强险默认值    
    third_tax:[],          //第三者责任险
    third_default: 1,    //第三者责任险默认值        
    glass_tax: [],         //玻璃单独破碎险
    glass_default: 0,         //玻璃破碎险默认值
    personnel_tax: [],     //车上人员责任险
    personnel_default: 0,     //车上人员责任险默认值
    scratch_tax: [],       //划痕
    scratch_default:1,       //划痕默认值
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    var that = this;

    //车型名称
    var car_name = options.car_name;
    //车型名称
    var naked_price = options.naked_price;

    if (car_name == undefined || car_name == ''){
      wx.showToast({
        title: '参数不正确',
        icon: 'none',
        duration: 2000
      });
    }

    if (naked_price == undefined || naked_price == '') {
      wx.showToast({
        title: '参数不正确',
        icon: 'none',
        duration: 2000
      });
    }

    that.setData({
      car_name: car_name,
      naked_price: naked_price
    })


    //车船税
    try {
      var vehicle_tax = wx.getStorageSync('vehicle_tax')
      if (vehicle_tax) {
        var vehicle_default = that.str2num(that.data.vehicle_default);//默认值
        var vehicle_tax_fee = vehicle_tax[vehicle_default].price;

        //交强险
        var constraint_tax = wx.getStorageSync('constraint_tax')
        var constraint_default = that.str2num(that.data.constraint_default);//默认值
        var constraint_tax_fee = constraint_tax[constraint_default].price

        //第三者责任险
        var third_tax = wx.getStorageSync('third_tax')
          var third_default = that.str2num(that.data.third_default);//默认值
          var third_tax_fee = third_tax[third_default].price

        //玻璃破碎险任险
          var glass_tax = wx.getStorageSync('glass_tax')
       
            var glass_default = that.str2num(that.data.glass_default);//默认值
            var glass_fee = glass_tax[glass_default].price
        
        //车上人责任险
          var personnel_tax = wx.getStorageSync('personnel_tax')
            var personnel_default = that.str2num(that.data.personnel_default);//默认值
            var person_duty_fee = personnel_tax[personnel_default].price
        
        //车身划损险
          var scratch_tax = wx.getStorageSync('scratch_tax')
            var scratch_default = that.str2num(that.data.scratch_default);//默认值
            var scratch_fee = scratch_tax[scratch_default].price
      
        that.setData({
          vehicle_tax: vehicle_tax,
          vehicle_tax_fee: vehicle_tax_fee,
          //交强险
          constraint_tax: constraint_tax,
          constraint_tax_fee: constraint_tax_fee,
          //第三者责任险
          third_tax: third_tax,
          third_tax_fee: third_tax_fee,
          //玻璃破碎险任险
          glass_tax: glass_tax,
          glass_fee: glass_fee,
          //车上人责任险
          personnel_tax: personnel_tax,
          person_duty_fee: person_duty_fee,
          //车身划损险
          scratch_tax: scratch_tax,
          scratch_fee: scratch_fee
        });
      }else{
        that.getCalAttr();
      }
    } catch (e) {
      that.getCalAttr();
    }
    //交强险
    // try {
    //   var constraint_tax = wx.getStorageSync('constraint_tax')
    //   if (constraint_tax) {
    //     var constraint_default = that.str2num(that.data.constraint_default);//默认值
    //     var constraint_tax_fee = constraint_tax[constraint_default].price
    //     that.setData({
    //       constraint_tax: constraint_tax,
    //       constraint_tax_fee: constraint_tax_fee
    //     });
    //   } else {
    //     that.getCalAttr();
    //   }
    // } catch (e) {
    //   that.getCalAttr();
    // }

    //第三者责任险
    // try {
    //   var third_tax = wx.getStorageSync('third_tax')
    //   if (third_tax) {
    //     var third_default = that.str2num(that.data.third_default);//默认值
    //     var third_tax_fee = third_tax[third_default].price
    //     that.setData({
    //       third_tax: third_tax,
    //       third_tax_fee: third_tax_fee
    //     });
    //   } else {
    //     that.getCalAttr();
    //   }
    // } catch (e) {
    //   that.getCalAttr();
    // }

    //玻璃破碎险任险
    // try {
    //   var glass_tax = wx.getStorageSync('glass_tax')
    //   if (glass_tax) {
    //     var glass_default = that.str2num(that.data.glass_default);//默认值
    //     var glass_fee = glass_tax[glass_default].price
    //     that.setData({
    //       glass_tax: glass_tax,
    //       glass_fee: glass_fee
    //     });
    //   } else {
    //     that.getCalAttr();
    //   }
    // } catch (e) {
    //   that.getCalAttr();
    // }

    //车上人责任险
    // try {
    //   var personnel_tax = wx.getStorageSync('personnel_tax')
    //   if (personnel_tax) {
    //     var personnel_default = that.str2num(that.data.personnel_default);//默认值
    //     var person_duty_fee = personnel_tax[personnel_default].price
    //     that.setData({
    //       personnel_tax: personnel_tax,
    //       person_duty_fee: person_duty_fee
    //     });
    //   } else {
    //     that.getCalAttr();
    //   }
    // } catch (e) {
    //   that.getCalAttr();
    // }

    //车身划损险
    // try {
    //   var scratch_tax = wx.getStorageSync('scratch_tax')
    //   if (scratch_tax) {
    //     var scratch_default = that.str2num(that.data.scratch_default);//默认值
    //     var scratch_fee = scratch_tax[scratch_default].price
    //     that.setData({
    //       scratch_tax: scratch_tax,
    //       scratch_fee: scratch_fee
    //     });
    //   } else {
    //     that.getCalAttr();
    //   }
    // } catch (e) {
    //   that.getCalAttr();
    // }

    console.log(vehicle_default)

    var vehicle_tax_fee = that.data.vehicle_tax;
    console.log(vehicle_tax_fee)


    //计算和初始化
    that.numeration();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.getCalAttr();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  tabClick: function (e) {  //car_info_height
    var id = e.currentTarget.id;
    if(id == 0){
      var car_info_height = 176;
    }else{
      car_info_height = 296;
    }
    this.setData({
      activeIndex: e.currentTarget.id,
      car_info_height: car_info_height
    });
  },
  /**
   * 切换首付款
   */
  changeNaked:function(e){
    this.choiceItem(e);
  },
  changeLoans:function(e){
    this.choiceItem(e,2);
  },
  /**
   * 点击选择首付款、贷款
   * 1:首付款
   * 2:贷款年限
   */
  choiceItem:function(e,c_type=1){
    var that = this;
    var sel_id = e.target.id;

    if (c_type == 1){
      var data = that.data.naked_ratio;
    }else{
      var data = that.data.loans;
    }

    for (var i in data) {
      if (sel_id == i) {
        data[i]['sel'] = 1;
      } else {
        data[i]['sel'] = 0;
      }
    }

    if (c_type == 1) {
      that.setData({
        naked_ratio: data
      });
    }else{
      that.setData({
        loans: data
      });
    }
    
    //重新计算
    that.numeration();
  },
  /**
   * 获取计算属性
   */
  getCalAttr:function(){

    var that = this;

    //请求获取计算属性
    api.get({
      url: 'portal/calculator/index',
      success: function(res) {
        console.log(res)
        if (res.code) {
          //车船税
          var vehicle_tax = res.data.vehicle_tax;
          var vehicle_default = that.data.vehicle_default;
          //交强险
          var constraint_tax = res.data.constraint_tax;
          //第三者责任险
          var third_tax = res.data.third_tax;
          //玻璃单独破碎险
          var glass_tax = res.data.glass_tax;
          //车上人员责任险
          var personnel_tax = res.data.personnel_tax;
          //车身划痕险
          var scratch_tax = res.data.scratch_tax;

          //缓存
          wx.setStorage({
            key: "vehicle_tax",
            data: vehicle_tax
          })
          wx.setStorage({
            key: "constraint_tax",
            data: constraint_tax
          })
          wx.setStorage({
            key: "third_tax",
            data: third_tax
          })
          wx.setStorage({
            key: "glass_tax",
            data: glass_tax
          })
          wx.setStorage({
            key: "personnel_tax",
            data: personnel_tax
          })
          wx.setStorage({
            key: "scratch_tax",
            data: scratch_tax
          })

          //更新AppData
          that.setData({
            vehicle_tax: vehicle_tax,
            vehicle_tax_fee: vehicle_tax[vehicle_default].price,
            constraint_tax: constraint_tax,
            third_tax: third_tax,
            glass_tax: glass_tax,
            personnel_tax: personnel_tax,
            scratch_tax: scratch_tax
          })

          //重新计算
          that.numeration();
        }
      },
      fail: err => {

      }
    });
  },
  /**
   * 车船税切换
   */
  vehicleChange:function(e){
    var that = this;
    var id = e.detail.value;
    var vehicle_tax_fee = that.data.vehicle_tax[id].price;

    that.setData({
      vehicle_default:id,
      vehicle_tax_fee: vehicle_tax_fee
    });

    //重新计算
    that.numeration();
  },
  constraintChange:function(e){   //交强险切换
    var that = this;
    var id = e.detail.value;
    var constraint_tax_fee = that.data.constraint_tax[id].price;

    that.setData({
      constraint_default: id,
      constraint_tax_fee: constraint_tax_fee
    });

    //重新计算
    that.numeration();
  },

  /**
   * 商业保险
   */
  sel_all:function(e){
    var that = this;
    var sel_all = this.data.sel_all;

    //点击马上切换状态
    sel_all = !sel_all;
    
    //勾选标志
    var third_sel = that.data.third_sel;               //第三者责任险
    var third_deduction_sel = that.data.third_deduction_sel;     //第三者不计免赔
    var loss_sel = that.data.loss_sel;                //车辆损失险
    var loss_deduction_sel = that.data.loss_deduction_sel;       //损失不计免赔
    var steal_sel = that.data.steal_sel;               //车辆盗抢险
    var glass_sel = that.data.glass_sel;               //玻璃单独破碎险
    var self_ignite_sel = that.data.self_ignite_sel;          //自燃损失险  
    var person_duty_sel = that.data.person_duty_sel;          //车上人员责任险
    var scratch_sel = that.data.scratch_sel;              //车身划痕险


    //如果“全选”选中，强制全部勾选
    if(sel_all){  //全选
      third_sel = true;               //第三者责任险
      third_deduction_sel = true;        //第三者不计免赔
      loss_sel = true;                  //车辆损失险
      loss_deduction_sel = true;        //损失不计免赔
      steal_sel = true;                //车辆盗抢险
      glass_sel = true;                //玻璃单独破碎险
      self_ignite_sel = true;           //自燃损失险  
      person_duty_sel = true;          //车上人员责任险
      scratch_sel = true;               //车身划痕险
    }else{
      third_sel = false;               //第三者责任险
      third_deduction_sel = false;        //第三者不计免赔
      loss_sel = false;                  //车辆损失险
      loss_deduction_sel = false;        //损失不计免赔
      steal_sel = false;                //车辆盗抢险
      glass_sel = false;                //玻璃单独破碎险
      self_ignite_sel = false;           //自燃损失险  
      person_duty_sel = false;          //车上人员责任险
      scratch_sel = false;               //车身划痕险
    }

    //选中刷新
    that.setData({
      sel_all: sel_all,

      third_sel: third_sel,               //第三者责任险
      third_deduction_sel: third_deduction_sel,      //第三者不计免赔
      loss_sel: loss_sel,                 //车辆损失险
      loss_deduction_sel: loss_deduction_sel,      //损失不计免赔
      steal_sel: steal_sel,               //车辆盗抢险
      glass_sel: glass_sel,               //玻璃单独破碎险
      self_ignite_sel: self_ignite_sel,         //自燃损失险  
      person_duty_sel: person_duty_sel,         //车上人员责任险
      scratch_sel: scratch_sel,             //车身划痕险
    })

    //重新计算
    that.numeration();
  },
  /**
   * 商业保险选中并计算价格
   */
  businessTaxSel:function(e){
    var that = this;
    var target = e.currentTarget.id;
    console.log(target)
    console.log(e)

    //勾选标志
    var third_sel = that.data.third_sel;               //第三者责任险
    var third_deduction_sel = that.data.third_deduction_sel;     //第三者不计免赔
    var loss_sel = that.data.loss_sel;                //车辆损失险
    var loss_deduction_sel = that.data.loss_deduction_sel;       //损失不计免赔
    var steal_sel = that.data.steal_sel;               //车辆盗抢险
    var glass_sel = that.data.glass_sel;               //玻璃单独破碎险
    var self_ignite_sel = that.data.self_ignite_sel;          //自燃损失险  
    var person_duty_sel = that.data.person_duty_sel;          //车上人员责任险
    var scratch_sel = that.data.scratch_sel;              //车身划痕险

    //声明费用
    var third_tax_fee = that.str2num(that.data.third_tax_fee);               //第三者责任险费用  
    var third_deduction_fee = that.str2num(that.data.third_deduction_fee);      //第三者不计免赔
    var loss_fee = that.str2num(that.data.loss_fee);                 //车辆损失险
    var loss_deduction_fee = that.str2num(that.data.loss_deduction_fee);      //损失不计免赔
    var steal_fee = that.str2num(that.data.steal_fee);               //车辆盗抢险
    var glass_fee = that.str2num(that.data.glass_fee);               //玻璃单独破碎险
    var self_ignite_fee = that.str2num(that.data.self_ignite_fee);         //自燃损失险  
    var person_duty_fee = that.str2num(that.data.person_duty_fee);         //车上人员责任险
    var scratch_fee = that.str2num(that.data.scratch_fee);            //车身划痕险 

    switch (target){
      case 'third_sel':
        third_sel = !third_sel;
        break;
      case 'third_deduction_sel':
        third_deduction_sel = !third_deduction_sel;
        break;
      case 'loss_sel':
        loss_sel = !loss_sel;
        break;
      case 'loss_deduction_sel':
        loss_deduction_sel = !loss_deduction_sel;
        break;
      case 'steal_sel':
        steal_sel = !steal_sel;
        break;
      case 'glass_sel':
        glass_sel = !glass_sel;
        break;
      case 'self_ignite_sel':
        self_ignite_sel = !self_ignite_sel;
        break;
      case 'person_duty_sel':
        person_duty_sel = !person_duty_sel;
        break;
      case 'scratch_sel':
        scratch_sel = !scratch_sel;
        break;
      default:
        return;
        break;
    }

    //如果全部都勾选龙，“全选”自动为true
    var sel_all = that.data.sel_all;  //全选标志

    if (third_sel && third_deduction_sel && loss_sel && loss_deduction_sel && steal_sel && glass_sel && self_ignite_sel && person_duty_sel && scratch_sel){
      sel_all = true;
    }else{
      sel_all = false;
    }

    //选中刷新
    that.setData({
      sel_all: sel_all,   //全选

      third_sel: third_sel,               //第三者责任险
      third_deduction_sel: third_deduction_sel,      //第三者不计免赔
      loss_sel: loss_sel,                 //车辆损失险
      loss_deduction_sel: loss_deduction_sel,      //损失不计免赔
      steal_sel: steal_sel,               //车辆盗抢险
      glass_sel: glass_sel,               //玻璃单独破碎险
      self_ignite_sel: self_ignite_sel,         //自燃损失险  
      person_duty_sel: person_duty_sel,         //车上人员责任险
      scratch_sel: scratch_sel,             //车身划痕险
    })

    //重新计算
    that.numeration();
  },
  thirdChange: function (e) {//第三者责任险切换 glassChange
    var that = this;
    var id = e.detail.value;
    
    var third_tax_fee = that.data.third_tax[id].price;

    that.setData({
      third_default: id,
      third_tax_fee: third_tax_fee
    });

    //重新计算
    that.numeration();
  },
  glassChange: function (e) {//玻璃破碎切换 
    var that = this;
    var id = e.detail.value;

    var glass_fee = that.data.glass_tax[id].price;

    that.setData({
      glass_default: id,
      glass_fee: glass_fee
    });

    //重新计算
    that.numeration();
  },
  personnelChange: function (e) {//车上人员责任险 
    var that = this;
    var id = e.detail.value;

    var person_duty_fee = that.data.personnel_tax[id].price;

    that.setData({
      personnel_default: id,
      person_duty_fee: person_duty_fee
    });

    //重新计算
    that.numeration();
  },
  scratchChange: function (e) {//车身划损险 
    var that = this;
    var id = e.detail.value;

    var scratch_fee = that.data.scratch_tax[id].price;

    that.setData({
      scratch_default: id,
      scratch_fee: scratch_fee
    });

    //重新计算
    that.numeration();
  },

  /**
   * 初始化数据，计算总数
   */
  numeration:function(){
    var that = this;

    //获取裸车价
    var naked_price = that.str2num(that.data.naked_price);

    //计算购置税
    var purchase_tax_fee = parseInt(naked_price/11.7);
    console.log(purchase_tax_fee)

    //消费税
    var consumption_tax_fee = that.str2num(that.data.consumption_tax_fee);

    //上牌费用
    var apply_vehicle_fee = that.str2num(that.data.apply_vehicle_fee);
    
    //车船税
    var vehicle_tax_fee = that.str2num(that.data.vehicle_tax_fee);
    
    //交强险
    var constraint_tax_fee = that.str2num(that.data.constraint_tax_fee);

    //必须花费
    var must_pay_fee = purchase_tax_fee + consumption_tax_fee + apply_vehicle_fee + vehicle_tax_fee + constraint_tax_fee;

    /**
     * 商业保险计费
     */
    //声明费用
    var third_tax_fee = that.str2num(that.data.third_tax_fee);               //第三者责任险费用  
    var third_deduction_fee = that.str2num(that.data.third_deduction_fee);      //第三者不计免赔
    var loss_fee = that.str2num(that.data.loss_fee);                 //车辆损失险
    var loss_deduction_fee = that.str2num(that.data.loss_deduction_fee);      //损失不计免赔
    var steal_fee = that.str2num(that.data.steal_fee);               //车辆盗抢险
    var glass_fee = that.str2num(that.data.glass_fee);               //玻璃单独破碎险
    var self_ignite_fee = that.str2num(that.data.self_ignite_fee);         //自燃损失险  
    var person_duty_fee = that.str2num(that.data.person_duty_fee);         //车上人员责任险
    var scratch_fee = that.str2num(that.data.scratch_fee);            //车身划痕险 
    //勾选标志
    var third_sel = that.data.third_sel;               //第三者责任险
    var third_deduction_sel = that.data.third_deduction_sel;     //第三者不计免赔
    var loss_sel = that.data.loss_sel;                //车辆损失险
    var loss_deduction_sel = that.data.loss_deduction_sel;       //损失不计免赔
    var steal_sel = that.data.steal_sel;               //车辆盗抢险
    var glass_sel = that.data.glass_sel;               //玻璃单独破碎险
    var self_ignite_sel = that.data.self_ignite_sel;          //自燃损失险  
    var person_duty_sel = that.data.person_duty_sel;          //车上人员责任险
    var scratch_sel = that.data.scratch_sel;              //车身划痕险

    //计算商业保险总数 business_fee
    var business_fee = 0;
    if (third_sel) business_fee += third_tax_fee;
    if (third_deduction_sel) business_fee += third_deduction_fee;
    if (loss_sel) business_fee += loss_fee;
    if (loss_deduction_sel) business_fee += loss_deduction_fee;
    if (steal_sel) business_fee += steal_fee;
    if (glass_sel) business_fee += glass_fee;
    if (self_ignite_sel) business_fee += self_ignite_fee;
    if (person_duty_sel) business_fee += person_duty_fee;
    if (scratch_sel) business_fee += scratch_fee;

    //总费用
    var total_price = naked_price + must_pay_fee + business_fee;

    /*分期计算 start */
    var loans_total_price = 0; //贷款多总价格
    var down_payment = 0;    //首付总款
    var monthly_payment = 0;      //月供
    var more_expenditure = 0;       //比全款多花
    var monthly_interest = that.data.monthly_interest;   //贷款月息

    var down_payment_rate = 0.3;  //首付百分比
    var down_payment_months = 36;  //分期月数

    //取最新百分比和年限
    var naked_ratio = that.data.naked_ratio;  //首付款data
    var loans = that.data.loans;  //贷款年限data

    for (var i in naked_ratio) {
      if (naked_ratio[i]['sel'] == 1) {
        down_payment_rate = naked_ratio[i]['val'];
      } 
    }
    for (var j in loans) {
      if (loans[j]['sel'] == 1) {
        down_payment_months = loans[j]['val'];
      }
    }
    //首付 = 裸车价*首付款百分比 + 必须花费 + 商业保险
    down_payment = parseInt(naked_price * down_payment_rate) + must_pay_fee + business_fee;

    //月供 = 剩余款/月数 + 剩余款*月费率
    monthly_payment = parseInt((total_price - down_payment) / down_payment_months) + parseInt((total_price - down_payment) * monthly_interest);

    //比全款多花多钱 = 月供 * 月数 + 首付 - 全款总价
    more_expenditure = parseInt(monthly_payment * down_payment_months) + down_payment - total_price;
    
    //贷款预计总费用 = 首付 + 月供 * 月数
    loans_total_price = down_payment + monthly_payment * down_payment_months

    //设置数据
    that.setData({
      purchase_tax_fee: app.toThousands(purchase_tax_fee),
      must_pay_fee: app.toThousands(must_pay_fee),
      /* 商业总费用 */
      business_fee: app.toThousands(business_fee),
      total_price: app.toThousands(total_price),

      //贷款数据
      loans_total_price: app.toThousands(loans_total_price), //贷款总款
      down_payment: app.toThousands(down_payment),            //首付
      monthly_payment: app.toThousands(monthly_payment),     //月供
      more_expenditure: app.toThousands(more_expenditure),   //比全款多花

    })
  },
 
  /**
   * 字符串转化为数字
   */
  str2num:function(str){
    if (typeof str == 'string'){
      return Number(str.replace(/,/g, ''))
    }else{
      return Number(str);
    }
  }
})